<?php
class Randstand_Net_Socket_Server_Client
{
    /**
     * Client socket handle
     *
     * @var Resource
     */
    private $_handle = null;
    
    /**
     * Unique token
     *
     * @var string
     */
    private $_token = null;
    
    /**
     * The current incoming message
     *
     * @var string
     */
    private $_currentRequest = null;
    
    /**
     * If the client is logged in, it
     * gets a user id
     *
     * @var int
     */
    private $_userId = -1;
    
    /**
     * Constructor
     *
     * @param Resource $argHandle The open socket for the client
     */
    function __construct($argHandle)
    {
        $this->_handle = $argHandle;
        $this->_token = substr(md5(microtime(true).mt_rand()), 0, 8);
        $this->_currentRequest = '';
    }
    
    
    /**
     * Return the socket handle
     *
     * @return Resource
     */
    public function getHandle()
    {
        return $this->_handle;
    }
    
    
    /**
     * Return unique token
     *
     * @return string
     */
    public function getToken()
    {
        return $this->_token;
    }
    
    
    /**
     * Appends a character or string to the
     * incoming message
     *
     * @param string $argText
     * @return this
     */
    public function appendRequest($argText)
    {
        $this->_currentRequest .= $argText;
        return $this;
    }
    
    
    /**
     * Clear message
     *
     * @return this
     */
    public function clearRequest()
    {
        $this->_currentRequest = '';
        return $this;
    }
    
    
    /**
     * Returns the message
     *
     * @return string
     */
    public function getRequest()
    {
        return $this->_currentRequest;
    }
    
    
    /**
     * Enter description here...
     *
     * @param unknown_type $argMsg
     */
    public function sendMessage($argMsg)
    {
        socket_write($this->_handle, $argMsg);
    }
}
?>
